// JQuery hover event with timeout by Taufik Nurrohman
// https://plus.google.com/108949996304093815163/about
(function($) {
    $.fn.hoverTimeout = function(timeout1, fn1, timeout2, fn2) {
        return this.each(function() {
            var t = null, $this = $(this);
            $this.hover(function() {
                clearTimeout(t);
                t = setTimeout(function() {
                    fn1.call($this);
                }, timeout1);
            }, function() {
                clearTimeout(t);
                t = setTimeout(function() {
                    fn2.call($this);
                }, timeout2);
            });
        });
    };
})(jQuery);

var numposts   = 5,
    cmtext     = "Comment",
    pBlank     = "http://1.bp.blogspot.com/-htG7vy9vIAA/Tp0KrMUdoWI/AAAAAAAABAU/e7XkFtErqsU/s1600/grey.gif",
    pkBlank     = "http://2.bp.blogspot.com/-5sosqbvgRi4/UW4zbrXesJI/AAAAAAAABPs/pTP4l9VamM4/s1600/4TNP04I0VDET.JPG",
    numcomment = 5,
    cmsumm     = 80,
    adminBlog  = "Sam";

// RECENT POSTS
// VISIT: http://hompimpaalaihumgambreng.blogspot.com
// Recent Post with Thumbnail

function dropdownposts(f){var g=f.feed.entry;for(var e=0;e<numposts;e++){var c;for(var d=0;d<g[e].link.length;d++){if(g[e].link[d].rel=="alternate"){c=g[e].link[d].href;break}}for(var b=0;b<g[e].link.length;b++){if(g[e].link[b].rel=="replies"&&g[e].link[b].type=="text/html"){cmnum=g[e].link[b].title.split(" ")[0];break}}var h=g[e].title.$t,a=g[e].published.$t.substring(0,10),a=a.replace(/-/g,"/");if("media$thumbnail" in g[e]){postimg=g[e].media$thumbnail.url}else{postimg=pBlank}document.write('<li><a class="thumrc" href="'+c+'"><img src="'+postimg+'" class="rp-thumb" alt="thumb" /></a>');document.write('<div class="infrent"><a href="'+c+'">'+h+'</a><span class="footer-outer"><span class="dt">'+a+'</span><span class="cm"> - '+cmnum+" "+cmtext+"</span></span></div></li>")}}

function createCookie(name, value, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		var expires = "; expires=" + date.toGMTString();
	} else {
		var expires = "";
	}
	document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for (var i = 0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0) == ' ') c = c.substring(1, c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name, "", -1);
}

(function($) {
	$.fn.toggleSidebar = function(config) {

		config = $.extend({
			expand: "#main-wrapper",  // Your expandable element
			hideText: "(-)", // Toggle button label when the sidebar is visible
			showText: "(+)", // Toggle button label when the sidebar is hidden
			animated: true,          // If true, then the animation will be enabled
			animateSpeed: 400,        // Your animation speed
			extraWidth: 0,
			easingType: null,         // Your animation easing type
			enableCookie: false,      // If true, the browser will save the 'hidden/visible sidebar' session (JavaScript Cookie is required!)
			cookieName: 'sidebar-session',
			expires: 7000,
			insertNav: true,           // Automatically insert a toggle button above the sidebar (column)
			defaultHidden: false       // If true, the sidebar will be hidden by default
		}, config);

		// Build a toggle button above the sidebar
		if(config.insertNav) {
			$(config.expand).before('<div id="sidebar-toggler-wrapper" title="Hide Sidebar"><a class="sidebar-toggler from-js" href="#">' + config.hideText + '</a><div style="clear:both;"></div></div>');
		}

		var $this = this,
			$toggler = $('.sidebar-toggler'),
			sidebarWidth = $this.outerWidth() + config.extraWidth, // width + padding + border-width (if any) + extra_width
			expanderWidth = $(config.expand).width(); // width

		function hideSidebar() {
			if(config.animated) {
				$this.stop(true,true).fadeOut(config.animateSpeed/2, function() {
					$(config.expand).animate({width:expanderWidth+sidebarWidth}, config.animateSpeed, config.easingType);
				});
			} else {
				$this.hide();
				$(config.expand).css('width', expanderWidth+sidebarWidth);
			}
			if(config.enableCookie) {
				if(!config.defaultHidden) {
					createCookie(config.cookieName, null, config.expires);
				} else {
					eraseCookie(config.cookieName);
				}
			}
		}
		function showSidebar() {
			if(config.animated) {
				$(config.expand).stop().animate({width:expanderWidth}, config.animateSpeed, config.easingType, function() {
					$this.fadeIn(config.animateSpeed);
				});
			} else {
				$this.show();
				$(config.expand).css('width', expanderWidth);
			}
			if(config.enableCookie) {
			if(!config.defaultHidden) {
					eraseCookie(config.cookieName);
				} else {
					createCookie(config.cookieName, null, config.expires);
				}
			}
		}

		if(config.defaultHidden) {
			if(readCookie(config.cookieName)) {
				$toggler.removeClass('active').html(config.hideText);
				$this.show();
				$(config.expand).css('width', expanderWidth);
			} else {
				$toggler.addClass('active').html(config.showText);
				$this.hide();
				$(config.expand).css('width', expanderWidth+sidebarWidth);
			}
		} else {
			if(readCookie(config.cookieName)) {
				$toggler.addClass('active').html(config.showText);
				$this.hide();
				$(config.expand).css('width', expanderWidth+sidebarWidth);
			}
		}

		$toggler.on("click", function() {
			if($this.is(':hidden')) {
				showSidebar();
				$(this).removeClass('active').html(config.hideText);
			} else {
				hideSidebar();
				$(this).addClass('active').html(config.showText);
			}
			return false;
		});

	};
})(jQuery);

$(function() {
    $('#sidebar-wrapper').toggleSidebar({
        expand: "#main-wrapper"
    });
});